package com.JL.test;

import com.JL.engine.View.AnimationView;
import com.JL.engine.View.RectView;
import com.JL.engine.components.CollisionComponent;
import com.JL.engine.components.IdComponent;
import com.JL.engine.components.ViewComponent;
import com.JL.engine.model.Entity;
import com.JL.engine.model.EntityFactory;
import com.JL.engine.model.InitData;
import com.JL.engine.util.AssetsLoader;

import java.awt.*;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class PlayerEntityFactory implements EntityFactory {
    private int i;
    @Override
    public String getEntityName(){
        return "player";
    }
//    @Override
//    public Entity create(InitData initData){
//        Entity player = new Entity();
//        player.setPosition(initData.getPoint());
//        player.setSize(initData.getDimension());
//        Color color = initData.getOption("color");
//        player.addView(new RectView(0,100,100,color,true));
//
//        player.addView(new RectView(1,10,10,20,20,Color.BLACK,true));
//        player.addView(new RectView(1, player.getWidth()-30,10,20,20,Color.BLACK,true ));
//        player.addView(new RectView(1,10, player.getHeight()-30,20,20,Color.BLACK,true ));
//        player.addView(new RectView(1,player.getWidth()-30, player.getHeight()-30,20,20,Color.BLACK,true ));
//
//        ViewComponent component = player.getComponent(ViewComponent.class);
//        component.setZIndex(initData.get("zindex",0));
//        return player;
//    }

    @Override
    public Entity create(InitData initData) throws IOException {
        Entity player = new Entity();
        player.addComponent(new IdComponent(initData.getOption("id")));
        player.addComponent(new MoveComponent());
        player.setPosition(initData.getPoint());
        player.setSize(initData.getDimension());
        CollisionComponent collisionComponent = new CollisionComponent();
        collisionComponent.addHotRectangle("左上角",new Rectangle(10,10,20,20));
        collisionComponent.addHotRectangle("右上角",new Rectangle(player.getWidth()-30,10,20,20));
        collisionComponent.addHotRectangle("左下角",new Rectangle(10,player.getHeight()-30,20,20));
        collisionComponent.addHotRectangle("右下角",new Rectangle(player.getWidth()-30,player.getHeight()-30,20,20));
        collisionComponent.setType(initData.getOption("type"));
        player.addComponent(collisionComponent);
        return player;
    }
}